<?php


namespace app\shop\controller\pc;


use app\BaseController;
use app\shop\service\chat\MessageService;

class ChatRecordController extends BaseController
{
    /**
     *
     * @return \think\response\Json
     */
    public function getMessageRecord()
    {
        try {
            $upPage = $this->request->param('up_page', 1, 'int');
            $downPage = $this->request->param('down_page', 1, 'int');
            $listRows = $this->request->param('limit', 10, 'int');
            $isFirst = $this->request->param('is_first', 1, 'int');
            $msgId = $this->request->param('msg_id', 0, 'int');
            $toContactId = $this->request->param('toContactId', 0, 'int');
            $search = $this->request->param('search', '', 'trim');
            $fromUid = $this->request->param('fromUid', 0, 'int');
            // 0下拉加载以前的消息 1上拉加载以后的消息
            $directional = $this->request->param('directional', 1, 'int');
            $userId = $this->request->middleware('userId');
            $userId = $fromUid ?: $userId;

            $list = MessageService::getMessageRecord($msgId, $userId, $toContactId, $listRows, $isFirst, $directional, $upPage, $downPage, $search);
            return $this->success($list);
        } catch (\Exception $exception) {
            return $this->error($exception->getMessage());
        }
    }
}